package xyz.wadewhy.basicstest.designPatterns.BuilderPattern;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 手机类
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
class Phone {
    private String cpu;
    private String backCover;
    private String screen;
}

/**
 * 手机build抽象类
 */
abstract class PhoneBuild {
    protected Phone phone = new Phone();

    /**
     * 获得手机
     *
     * @return
     */
    abstract Phone getPhone();

    /**
     * cpu生产
     */
    abstract void buildCpu();

    /**
     * 后壳生产
     */
    abstract void buildBackCover();

    /**
     * 屏幕生产
     */
    abstract void buildScreen();

}

/**
 * 华为手机build
 */
class HuaWeiBuild extends PhoneBuild {

    @Override
    Phone getPhone() {
        return phone;
    }

    @Override
    void buildCpu() {
        phone.setCpu("麒麟奶奶挺芯片....");
    }

    @Override
    void buildBackCover() {
        phone.setBackCover("陶瓷工艺后壳....");
    }

    @Override
    void buildScreen() {
        phone.setScreen("大猩猩🦍玻璃....");
    }
}

/**
 * 苹果手机build
 */
class ApplePhoneBuild extends PhoneBuild {

    @Override
    Phone getPhone() {
        return phone;
    }

    @Override
    void buildCpu() {
        phone.setCpu("A12芯片");
    }

    @Override
    void buildBackCover() {
        phone.setBackCover("玻璃后壳");
    }

    @Override
    void buildScreen() {
        phone.setScreen("三星屏幕");
    }
}

class Director {
    /**
     *
     */
    private final PhoneBuild phoneBuilder;

    public Director(PhoneBuild phoneBuilder) {
        this.phoneBuilder = phoneBuilder;
    }

    /**
     * 构建手机
     *
     * @return Phone
     */
    public Phone construct() {
        phoneBuilder.buildCpu();
        phoneBuilder.buildScreen();
        phoneBuilder.buildBackCover();
        return phoneBuilder.getPhone();
    }
}

class TestDemoV2 {
    public static void main(String[] args) {
        //传华为手机build
        Director director = new Director(new HuaWeiBuild());
        System.out.println(director.construct().toString());
        Director director2 = new Director(new ApplePhoneBuild());
        System.err.println(director2.construct().toString());
    }
}